package com.filmbooks.model.home.tabs;

import android.database.Observable;

import com.filmbooks.adapter.home.tabs.WangyiAdapter;
import com.filmbooks.api.WangyiApi;
import com.filmbooks.api.ZhihuApi;
import com.filmbooks.contract.home.tabs.WangyiContract;
import com.filmbooks.model.home.bean.home.WangyiNewsListBean;
import com.filmbooks.model.home.bean.home.ZhihuDailyListBean;
import com.zyw.horrarndoo.sdk.config.DBConfig;
import com.zyw.horrarndoo.sdk.config.ItemState;
import com.zyw.horrarndoo.sdk.helper.RetrofitCreateHelper;
import com.zyw.horrarndoo.sdk.helper.RxHelper;
import com.zyw.horrarndoo.sdk.utils.AppUtils;
import com.zyw.horrarndoo.sdk.utils.DBUtils;

import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;

/**
 * Created by heshuxiang on 2018/3/1.
 * 描述：
 * 公司：盟将威
 * 作者：heshuxiang
 * 日期：2018/3/1.
 * 工程：FilmBooks
 * 包：com.filmbooks.model.home.tabs
 */

public class WangyiModel implements WangyiContract.IWangyiModel {


    @Override
    public io.reactivex.Observable<WangyiNewsListBean> getNewsList(int id) {
        return RetrofitCreateHelper.createApi(WangyiApi.class, WangyiApi.HOST).getNewsList(id).compose(RxHelper.<WangyiNewsListBean>rxSchedulerHelper());
    }

    @Override
    public io.reactivex.Observable<Boolean> recordItemIsRead(final String key) {
        return io.reactivex.Observable.create(new ObservableOnSubscribe<Boolean>() {
            @Override
            public void subscribe(ObservableEmitter<Boolean> e) throws Exception {
                e.onNext(DBUtils.getDB(AppUtils.getContext()).insertRead(DBConfig
                        .TABLE_WANGYI, key, ItemState.STATE_IS_READ));
                e.onComplete();
            }
        }).compose(RxHelper.<Boolean>rxSchedulerHelper());
    }

    public static WangyiContract.IWangyiModel newInstance() {
        return new WangyiModel();
    }
}
